﻿using System;
using System.Text;

namespace IndirectX.Shaders
{
    public struct ChunkTag
    {
        public static ChunkTag RDEF = "RDEF"; // Resource Definition
        public static ChunkTag ISGN = "ISGN"; // Input Signature
        public static ChunkTag OSGN = "OSGN"; // Output Signature
        public static ChunkTag OSG5 = "OSG5"; // Output Signature
        public static ChunkTag SHEX = "SHEX"; // Shader
        public static ChunkTag SHDR = "SHDR"; // Shader
        public static ChunkTag STAT = "STAT"; // Statistics
        public static ChunkTag IFCE = "IFCE"; // Interface
        public static ChunkTag PCGS = "PCGS"; // Patch Constant Signature

        public uint Value;

        public ChunkTag(uint value) : this()
        {
            this.Value = value;
        }

        public static implicit operator ChunkTag(string tag)
        {
            var bytes = ASCIIEncoding.ASCII.GetBytes(tag);
            return new ChunkTag((uint)((bytes[0] | (bytes[1] << 8) | (bytes[2] << 16) | (bytes[3] << 24))));
        }

        public static implicit operator ChunkTag(uint tag)
        {
            return new ChunkTag(tag);
        }

        public static implicit operator uint(ChunkTag tag)
        {
            return tag.Value;
        }

        public override string ToString()
        {
            var bytes = BitConverter.GetBytes(Value);
            return ASCIIEncoding.ASCII.GetString(bytes);
        }
    }
}